<script setup lang="ts">
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
// import { usePageAuth } from '@/hooks/usePageAuth'
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
import { useLocationChange } from '@/hooks/useLocationChange'
import { uploadWorkerLocation, } from '@/api/order'
import { useGeoStore } from '@/store'
// usePageAuth()

const geoStore = useGeoStore()
const { currentLocation, startListen, stopListen } = useLocationChange(
  async (location) => {
    // console.log('位置变化🍌:', {location})
    const { longitude, latitude } = location
    await uploadWorkerLocation({ longitude, latitude })
    geoStore.setGeoInfo({
      longitude,
      latitude,
      updateTime: new Date().toLocaleString()
    })
    // {
    //   "latitude": 31.16561880015148,
    //   "longitude": 121.33106196435156,
    //   "accuracy": 89,
    //   "speed": 0,
    //   "altitude": 0,
    //   "verticalAccuracy": 0,
    //   "horizontalAccuracy": 89,
    //   "errMsg": "getLocation:ok"
    // }
    // 在这里处理位置变化逻辑
  },
  {
    throttleTime: 2000, // 2秒节流
    highAccuracy: true // 使用高精度定位
  }
)
onLaunch(() => {
  startListen()
})
onShow(() => {
  console.log('App Show')
})
onHide(() => {
  stopListen()
})
</script>

<style lang="scss">
@import 'sard-uniapp/index.scss';
swiper,
scroll-view {
  flex: 1;
  height: 100%;
  overflow: hidden;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}
</style>
